package se.cbb.scripts;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

import se.cbb.misc.SequenceFileWriter;

public class MotifSpeciesExtractor {

	public static void main(String[] args) {
		try {
			String path = "/Users/rhali/Desktop/";

			String fileName = path + "Synteny.hsf";
			String fileName1 = path + "Blast Results.txt";
			
			ArrayList<String> speciesName = new ArrayList<String>();
			ArrayList<String> geneName = new ArrayList<String>();
			
			BufferedReader bufferedreader = new BufferedReader(new FileReader(fileName));
			String str;
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				speciesName.add(strArr[0]);
				geneName.add(strArr[2]);
			}
			bufferedreader.close();
			
			bufferedreader = new BufferedReader(new FileReader(fileName1));
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				for(int i = 0; i < geneName.size(); i++) {
					if(geneName.get(i).equals(strArr[3])) {
						SequenceFileWriter.writeAndAppendLine(path, "BlastresWithSpecies.bl", str + "\t" + speciesName.get(i));
					}
				}
			}
			bufferedreader.close();
			
		} catch (Exception e) {
			System.out.println("Error : " + e.getMessage());
		}

	}

}
